<?php

class OAuth_Http_Response
{

    protected $_responseCode = null;

    protected $_headers = array();

    protected $_body = null;

    public function __construct($code, array $headers, $body = null)
    {
        $this->_responseCode = $code;
        $this->_headers = $headers;
        $this->_body = $body;
    }

    public function getBody()
    {
        return $this->_body;
    }

    public function getStatus()
    {
        return $this->code;
    }

    public function getHeaders()
    {
        return $this->_headers;
    }

    public function getHeader($header)
    {
        $header = ucwords(strtolower($header));
        if (!is_string($header) || !isset($this->_headers[$header])) {
            return null;
        }
        return $this->_headers[$header];
    }

    public function isError()
    {
        $restype = floor($this->_responseCode / 100);
        if ($restype == 4 || $restype == 5) {
            return true;
        }
        return false;
    }

    public function isSuccessful()
    {
        $restype = floor($this->code / 100);
        if ($restype == 2 || $restype == 1) {
            return true;
        }
        return false;
    }

}